package cn.bluedot.framework.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {
	
	private static String defaultFormat = "yyyy-MM-dd HH:mm:ss";
	
	private static String yyyyMMddFormat = "yyyyMMdd";
	
	public static String formatTimeByDefault() {
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat(defaultFormat);
		String str = format.format(date);
		return str;
	}
	
	public static String formatTimeByYyyyMMddFormat() {
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat(yyyyMMddFormat);
		String str = format.format(date);
		return str;
	}
	
	public static int compareTime(String time1, String time2) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(defaultFormat);
		try {
			Date date1 = simpleDateFormat.parse(time1);
			Date date2 = simpleDateFormat.parse(time2);
			// 如果date1 大于 date2 返回1 否则返回0
			return date1.compareTo(date2);
		} catch (ParseException e) {
			e.printStackTrace();
			System.out.println("时间转换失败");
		}
		return 0;
	}

}
